/*  Game/Army Editor for yALB - Yet Another List Builder (roster Editor for Wargames/tabletop games).
    Copyright (C) 2008-2012  Daniel Ricardo Castro Alvarado

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.*/

#ifndef UNITOPTIONS_H
#define UNITOPTIONS_H

#include <QDialog>
#include <QHash>

#include "propertyform.h"
#include "actionwidget.h"

#include "../collections/optioncollection.h"


namespace Ui {
    class UnitOptions;
}

class UnitOptions : public QDialog
{
    Q_OBJECT

public:
    explicit UnitOptions(ItemSelector& _itemSelector, QWidget *parent = 0);
    ~UnitOptions();

    OptionCollection getUnitOptions(const OptionCollection& currentOptions);

public slots:
    void addCategory(const GameCategory &category, const QString &key);
    void updateCategory(const QString& oldKey, const GameCategory& newCategory,
                         const QString& newKey);
    void removeCategory(const QString& key);

    void addProperty(const GameProperty& property, const QString &key);
    void updateProperty(const QString& oldKey, const GameProperty& newProperty,
                         const QString& newKey);
    void removeProperty(const QString& key);

    /*void addColumn(const Column &column, const QString &key);
    void updateColumn(const QString& oldKey, const Column& newColumn,
                         const QString& newKey);
    void removeColumn(const QString& key);*/

    void clearAll();
    void clearAllCategories();
    void clearAllProperties();
    //void clearAllColumns();

private slots:
    void addOption(const UnitOption& option, const QString &key);
    void updateOption(const QString& oldKey, const UnitOption& newOption,
                         const QString& newKey);
    void removeOption(const QString& key);

    void on_optList_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
    void on_optAdd_clicked();
    void on_optUpdate_clicked();
    void on_optDelete_clicked();
    void on_optClone_clicked();
    void on_optSetPropertiesButton_clicked();

    void on_inheritOptionBox_stateChanged(int arg1);

protected:
    void changeEvent(QEvent *event);

private:
    Ui::UnitOptions *ui;
    QHash<QString, QTreeWidgetItem*> keyIndex;

    PropertyForm propertyForm;

    OptionCollection options;

    void connectSignals();
    void disconnectSignals();

    void removeAllFromUI();

    void clearOptionForm();

    void fillFromUnitOptions(const OptionCollection& currentOptions);
};

inline void UnitOptions::addProperty(const GameProperty &property, const QString &key) {
    propertyForm.addProperty(property, key);
}

inline void UnitOptions::updateProperty(const QString &oldKey, const GameProperty &newProperty,
                                         const QString &newKey) {
    propertyForm.updateProperty(oldKey, newProperty, newKey);
}

inline void UnitOptions::removeProperty(const QString &key) {
    propertyForm.removeProperty(key);
}

/*inline void UnitOptions::addColumn(const Column &column, const QString &key) {
    actionBox.addColumn(column, key);
}

inline void UnitOptions::updateColumn(const QString &oldKey, const Column &newColumn,
                                       const QString &newKey) {
    actionBox.updateColumn(oldKey, newColumn, newKey);
}

inline void UnitOptions::removeColumn(const QString &key) {
    actionBox.removeColumn(key);
}*/

#endif // UNITOPTIONS_H
